package kyssion.leetcode.num51_100;

public class code58_最后一个单词的长度 {
    public static void main(String[] args) {
        System.out.println(new code58_最后一个单词的长度().lengthOfLastWord(""));
    }

    public int lengthOfLastWord(String s) {
        int right = -1;
        int left = s.length() - 1;
        while (left >= 0) {
            if (right == -1 && s.charAt(left) != ' ') {
                right = left;
            }
            if (right != -1 && s.charAt(left) == ' ') {
                break;
            }
            left--;
        }
        left = left + 1;
        return right - left + 1;
    }
}
